package components;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Observable;
import java.util.Observer;

import synchronizer.StoryTimer;


public class Chapter implements Observer{

    private StoryTimer timer = null;
    private int startTime;
    private int duration;
    private HashMap <Integer,Scene> scenes;
    private Scene currentScene;

    public Chapter(int start, int duration){
        this.timer = StoryTimer.getInstance();
        this.startTime=start;
        this.duration = duration;
        timer.addObserver(this);
    }

    @Override
    public void update(Observable obs, Object obj) {
        System.out.println(timer.getRemTime() + " seconds Remaining");
        timer=(StoryTimer)obs;
        checkStartTimeAchieved(timer.getRemTime());
    }
    
    public void checkStartTimeAchieved(int remTime)
    {
    if (startTime==remTime)
    {
    	//Start showing scenes
    }
    }

	public void setDuration(int duration) {
		this.duration = duration;
	}

	public int getDuration() {
		return duration;
	}
	
	public void setStartTime(int start) {
		this.startTime = start;
	}

	public int getStartTime() {
		return startTime;
	}
	
	public void addScene(int sceneNumber, Scene s)
	{
		this.scenes.put(sceneNumber, s);
	}
	
	public HashMap<Integer,Scene> getSceneMap()
	{
		return scenes;
	}
	
	public Collection<Scene> getScenes(){
		return scenes.values();
	}
	
	public int getNumberOfScenes()
	{
	 return scenes.size();
	}

	public void setCurrentScene(int currentScene) {
		this.currentScene = scenes.get(currentScene);
	}

	public Scene getCurrentScene() {
		return currentScene;
	}
	
	public Scene getScene(int i)
	{
		return scenes.get(i);
	}

}
